/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.annuaireComp.clientUtils;

import fr.annuaireComp.entities.Personnel;
import java.text.SimpleDateFormat;

/**
 *
 * @author MiniK
 */
public class ProfileModel {
    
    public static final String DATE_FORMAT_PATTERN = "dd/MM/yyyy";
    public static final String SEXE_FEMME_LABEL = "Femme";
    public static final String SEXE_HOMME_LABEL = "Homme";
    public static final String FONCTION_UNDEFINED_LABEL = "*non defin*";
    
    public String idpersonnel;
   
    public String nom;
  
    public String prenom;
   
    public String dateNaissance;
  
    public String email;
  
    public String bureau;
 
    public String password;
   
    public String fonction;
    
    public String sexe;

   @Override
    public boolean equals(Object object) {
        if (!(object instanceof ProfileModel)) {
            return false;
        }
        ProfileModel other = (ProfileModel) object;
        if ((this.idpersonnel == null && other.idpersonnel != null) || (this.idpersonnel != null && !this.idpersonnel.equals(other.idpersonnel))) {
            return false;
        }
        return true;
    }


    public static ProfileModel buildProfileModel(Personnel pers) {
        ProfileModel viewPersoData = new ProfileModel();
        viewPersoData.idpersonnel = pers.getIdpersonnel().toString();
        viewPersoData.nom = pers.getNom();
        viewPersoData.prenom = pers.getPrenom();
        viewPersoData.email = pers.getEmail();
        viewPersoData.bureau = (pers.getBureau() == null || pers.getBureau().isEmpty()) ? FONCTION_UNDEFINED_LABEL : pers.getBureau();

        viewPersoData.fonction = pers.getIdfonction().getLibelle();

        viewPersoData.dateNaissance = new SimpleDateFormat(DATE_FORMAT_PATTERN).format(pers.getDateNaissance());

        viewPersoData.sexe = (pers.getSexe()) ? SEXE_FEMME_LABEL : SEXE_HOMME_LABEL;
        return viewPersoData;
    }
}
